/*	Interactive Gravitational Simulator
	Project: IGS Core
	File: Integrator.cpp
	Author: Mike Bantegui <mbante2@gmail.com>, Hofstra University 
	Copyright (C) 2012 - 2013 Mike Bantegui

	This file is part of the IGS software package for simulating
	the N-Body problem in real-time. This was developed as part
	of a departmental honors thesis project at Hofstra University
	in the Spring 2012 semester.

	IGS is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	IGS is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "Integrator.h"
#include "StringUtils.h"
#include <cassert>
#include <iostream>

namespace IGS
{

template <class T>
Integrator *CheckedCreate(const std::string name)
{
	Integrator *integrator = new T();
	assert(ToLower(integrator->Name()) == name);
	return integrator;
}

// Tries to instantiate an integrator by name.
// Returns null if the integrator name is invalid.
Integrator *CreateIntegrator(std::string name)
{
	name = ToLower(name);

	if (name == "euler")
		return CheckedCreate<Euler>(name);
	if (name == "symplectic-euler")
		return CheckedCreate<SymplecticEuler>(name);
	if (name == "euler-trapezoid")
		return CheckedCreate<EulerTrapezoid>(name);
	if (name == "leapfrog")
		return CheckedCreate<Leapfrog>(name);
#if DerivativeCount > 1
	if (name == "hermite")
		return CheckedCreate<Hermite>(name);
#endif
#if DerivativeCount > 2
	if (name == "hermite-6")
		return CheckedCreate<Hermite6>(name);
#endif

	std::cerr << "Integrator not recognized: " << name << std::endl;
	return NULL;
}

}